package com.cuanbobox.adapter;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cuanbobox.activity.MainActivity;
import com.cuanbobox.bean.PPTBean;
import com.cuanbobox.bean.WdsBean;
import com.cuanbobox.bean.WdsDataList;
import com.cuanbobox.cbavcx.R;
import com.cuanbobox.utils.ImgUtil;
import com.cuanbobox.utils.LogUtil;

import java.util.List;

public class PPTAdapter extends BaseQuickAdapter<PPTBean, BaseViewHolder> implements BaseQuickAdapter.OnItemClickListener {

    public PPTAdapter(List<PPTBean> list) {
        super(R.layout.adapter_ppt_item, list);
        setOnItemClickListener(this);
    }

    @Override
    protected void convert(BaseViewHolder helper, PPTBean item) {
        ImageView ivImg=helper.getView(R.id.ivImg);
        View vSel=helper.getView(R.id.vSel);
        try{
            ivImg.setImageBitmap(ImgUtil.getBitmapByBase64(item.getBase64img()));
        }catch (Exception e){
            LogUtil.addError("-----------------base64图片展示失败-------------------");
            LogUtil.addError(e);
        }
        helper.setText(R.id.tvPage,""+item.getPage());
        if(MainActivity.nowPage==item.getPage()){
            vSel.setVisibility(View.VISIBLE);
        }else{
            vSel.setVisibility(View.GONE);
        }
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        PPTBean bean=getItem(position);
        WdsDataList.add(">PPT_GoTo:"+bean.getPage()+".");
    }

}